/*
 * elf_header_type.h
 *
 *  Created on: Sep 2, 2012
 *      Author: aortegag
 */

#ifndef ELF_HDR_H_
#define ELF_HDR_H_

#include "elf_basic_types.h"

#define EI_NIDENT 	16

//! ELF Header structure for 32 bit architectures
typedef struct {
	unsigned char   e_ident[EI_NIDENT];
	Elf32_Half		e_type;
	Elf32_Half		e_machine;
	Elf32_Word		e_version;
	Elf32_Addr		e_entry;
	Elf32_Off		e_phoff;
	Elf32_Off		e_shoff;
	Elf32_Word		e_flags;
	Elf32_Half		e_ehsize;
	Elf32_Half		e_phentsize;
	Elf32_Half		e_phnum;
	Elf32_Half		e_shentsize;
	Elf32_Half		e_shnum;
	Elf32_Half		e_shstrndx;
}Elf32_Ehdr;

//! ELF Header structure for 64 bit architectures
typedef struct {
    unsigned char	e_ident[EI_NIDENT];
    Elf64_Half		e_type;
    Elf64_Half		e_machine;
    Elf64_Word		e_version;
    Elf64_Addr		e_entry;
    Elf64_Off		e_phoff;
    Elf64_Off		e_shoff;
    Elf64_Word		e_flags;
    Elf64_Half		e_ehsize;
    Elf64_Half		e_phentsize;
    Elf64_Half		e_phnum;
    Elf64_Half		e_shentsize;
    Elf64_Half		e_shnum;
    Elf64_Half		e_shstrndx;
} Elf64_Ehdr;

/**
 * \defgroup ELF Object File types
 *
 * @{
 */
#define ET_NONE		0 //!< No file type
#define ET_REL		1 //!< Relocatable file
#define	ET_EXEC		2 //!< Executable file
#define ET_DYN		3 //!< Shared object file
#define ET_CORE		4 //!< Core file
#define ET_LOPROC	0xff00 //!< Processor-specific
#define ET_HIPROC	0xffff //!< Processor-specific
/**@}*/

/**
 * \defgroup Machine type
 *
 * Requires architecture for an individual file
 *
 * @{
 */
#define EM_NONE 	0 //!< No machine
#define EM_M32 		1 //!< AT&T WE 32100
#define EM_SPARC 	2 //!< SPARC
#define EM_386 		3 //!< Intel 80386
#define EM_68K 		4 //!< Motorola 68000
#define EM_88K 		5 //!< Motorola 88000
#define EM_860 		7 //!< Intel 80860
#define EM_MIPS 	8 //!< MIPS RS3000
#define EM_S370		 9		/* IBM System/370 */
#define EM_MIPS_RS3_LE	10		/* MIPS R3000 little-endian */

#define EM_PARISC	15		/* HPPA */
#define EM_VPP500	17		/* Fujitsu VPP500 */
#define EM_SPARC32PLUS	18		/* Sun's "v8plus" */
#define EM_960		19		/* Intel 80960 */
#define EM_PPC		20		/* PowerPC */
#define EM_PPC64	21		/* PowerPC 64-bit */
#define EM_S390		22		/* IBM S390 */

#define EM_V800		36		/* NEC V800 series */
#define EM_FR20		37		/* Fujitsu FR20 */
#define EM_RH32		38		/* TRW RH-32 */
#define EM_RCE		39		/* Motorola RCE */
#define EM_ARM		40		/* ARM */
#define EM_FAKE_ALPHA	41		/* Digital Alpha */
#define EM_SH		42		/* Hitachi SH */
#define EM_SPARCV9	43		/* SPARC v9 64-bit */
#define EM_TRICORE	44		/* Siemens Tricore */
#define EM_ARC		45		/* Argonaut RISC Core */
#define EM_H8_300	46		/* Hitachi H8/300 */
#define EM_H8_300H	47		/* Hitachi H8/300H */
#define EM_H8S		48		/* Hitachi H8S */
#define EM_H8_500	49		/* Hitachi H8/500 */
#define EM_IA_64	50		/* Intel Merced */
#define EM_MIPS_X	51		/* Stanford MIPS-X */
#define EM_COLDFIRE	52		/* Motorola Coldfire */
#define EM_68HC12	53		/* Motorola M68HC12 */
#define EM_MMA		54		/* Fujitsu MMA Multimedia Accelerator*/
#define EM_PCP		55		/* Siemens PCP */
#define EM_NCPU		56		/* Sony nCPU embeeded RISC */
#define EM_NDR1		57		/* Denso NDR1 microprocessor */
#define EM_STARCORE	58		/* Motorola Start*Core processor */
#define EM_ME16		59		/* Toyota ME16 processor */
#define EM_ST100	60		/* STMicroelectronic ST100 processor */
#define EM_TINYJ	61		/* Advanced Logic Corp. Tinyj emb.fam*/
#define EM_X86_64	62		/* AMD x86-64 architecture */
#define EM_PDSP		63		/* Sony DSP Processor */

#define EM_FX66		66		/* Siemens FX66 microcontroller */
#define EM_ST9PLUS	67		/* STMicroelectronics ST9+ 8/16 mc */
#define EM_ST7		68		/* STmicroelectronics ST7 8 bit mc */
#define EM_68HC16	69		/* Motorola MC68HC16 microcontroller */
#define EM_68HC11	70		/* Motorola MC68HC11 microcontroller */
#define EM_68HC08	71		/* Motorola MC68HC08 microcontroller */
#define EM_68HC05	72		/* Motorola MC68HC05 microcontroller */
#define EM_SVX		73		/* Silicon Graphics SVx */
#define EM_ST19		74		/* STMicroelectronics ST19 8 bit mc */
#define EM_VAX		75		/* Digital VAX */
#define EM_CRIS		76		/* Axis Communications 32-bit embedded processor */
#define EM_JAVELIN	77		/* Infineon Technologies 32-bit embedded processor */
#define EM_FIREPATH	78		/* Element 14 64-bit DSP Processor */
#define EM_ZSP		79		/* LSI Logic 16-bit DSP Processor */
#define EM_MMIX		80		/* Donald Knuth's educational 64-bit processor */
#define EM_HUANY	81		/* Harvard University machine-independent object files */
#define EM_PRISM	82		/* SiTera Prism */
#define EM_AVR		83		/* Atmel AVR 8-bit microcontroller */
#define EM_FR30		84		/* Fujitsu FR30 */
#define EM_D10V		85		/* Mitsubishi D10V */
#define EM_D30V		86		/* Mitsubishi D30V */
#define EM_V850		87		/* NEC v850 */
#define EM_M32R		88		/* Mitsubishi M32R */
#define EM_MN10300	89		/* Matsushita MN10300 */
#define EM_MN10200	90		/* Matsushita MN10200 */
#define EM_PJ		91		/* picoJava */
#define EM_OPENRISC	92		/* OpenRISC 32-bit embedded processor */
#define EM_ARC_A5	93		/* ARC Cores Tangent-A5 */
#define EM_XTENSA	94		/* Tensilica Xtensa Architecture */
#define EM_NUM		95
/**@}*/

/**
 * \defgroup Object file version
 * @{
 */
#define EV_NONE		0 //!< Invalid version
#define EV_CURRENT	1 //!< Current version
/**@}*/

/**
 * \defgroup ELF Identification macros
 * @{
 */
#define EI_MAG0 	0 //!< File identification
#define EI_MAG1 	1 //!< File identification
#define EI_MAG2 	2 //!< File identification
#define EI_MAG3 	3 //!< File identification
#define EI_CLASS 	4 //!< File class
#define EI_DATA 	5 //!< Data encoding
#define EI_VERSION 	6 //!< File version
#define EI_OSABI	7 //!< OS/ABI Identification
#define EI_ABIVERSION	8 //!< ABI Version
#define EI_PAD 		9 //!< Start of padding bytes
#define EI_NIDENT 	16 //!< Size of e_ident[]
/**@}*/

/**
 * \defgroup ELF Magic number
 * @{
 */
#define ELFMAG0 0x7f //!< e_ident[EI_MAG0]
#define ELFMAG1 'E' //!< e_ident[EI_MAG1]
#define ELFMAG2 'L' //!< e_ident[EI_MAG2]
#define ELFMAG3 'F' //!< e_ident[EI_MAG3]
/**@*/

/**
 * \defgroup File's class or capacity
 * @{
 */
#define ELFCLASSNONE 	0 //!< Invalid class
#define ELFCLASS32 		1 //!< 32-bit objects
#define ELFCLASS64 		2 //!< 64-bit objects
/**@}*/

/**
 * \defgroup Data encoding of the processor specific data in the object file.
 * @{
 */
#define ELFDATANONE 0 //!<Invalid data encoding
#define ELFDATA2LSB 1 //!<See below
#define ELFDATA2MSB 2 //!<See below
/**@}*/

/**
 * \defgroup Operating System and ABI Identifiers, e_ident[EI_OSABI]
 *
 * @{
 */
#define ELFOSABI_NONE		0	/* UNIX System V ABI */
#define ELFOSABI_SYSV		0	/* Alias.  */
#define ELFOSABI_HPUX		1	/* HP-UX */
#define ELFOSABI_NETBSD		2	/* NetBSD.  */
#define ELFOSABI_GNU		3	/* Object uses GNU ELF extensions.  */
#define ELFOSABI_LINUX		ELFOSABI_GNU /* Compatibility alias.  */
#define ELFOSABI_SOLARIS	6	/* Sun Solaris.  */
#define ELFOSABI_AIX		7	/* IBM AIX.  */
#define ELFOSABI_IRIX		8	/* .  */
#define ELFOSABI_FREEBSD	9	/* FreeBSD.  */
#define ELFOSABI_TRU64		10	/* Compaq TRU64 UNIX.  */
#define ELFOSABI_MODESTO	11	/* Novell Modesto.  */
#define ELFOSABI_OPENBSD	12	/* OpenBSD.  */
#define ELFOSABI_ARM_AEABI	64	/* ARM EABI */
#define ELFOSABI_ARM		97	/* ARM */
#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
/**@}*/
#endif /* ELF_HDR_H_ */
